package com.supms.patrol.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.supms.patrol.domain.DailyInspectionItems;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.supms.patrol.domain.TourTestItems;
import com.supms.patrol.service.ITourTestItemsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 巡考内容项Controller
 * 
 * @author LiangHao
 * @date 2022-03-15
 */
@RestController
@RequestMapping("/tourTestItems")
public class TourTestItemsController extends BaseController
{
    @Autowired
    private ITourTestItemsService tourTestItemsService;

    /**
     * 查询巡考内容项列表
     */
    @RequiresPermissions("patrol:tourTestItems:list")
    @GetMapping("/list")
    public TableDataInfo list(TourTestItems tourTestItems)
    {
        startPage();
        List<TourTestItems> list = tourTestItemsService.selectTourTestItemsList(tourTestItems);
        return getDataTable(list);
    }

    /**
     * 导出巡考内容项列表
     */
    @RequiresPermissions("patrol:tourTestItems:export")
    @Log(title = "巡考内容项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TourTestItems tourTestItems)
    {
        List<TourTestItems> list = tourTestItemsService.selectTourTestItemsList(tourTestItems);
        ExcelUtil<TourTestItems> util = new ExcelUtil<TourTestItems>(TourTestItems.class);
        util.exportExcel(response, list, "巡考内容项数据");
    }

    /**
     * 获取巡考内容项详细信息
     */
    @RequiresPermissions("patrol:tourTestItems:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tourTestItemsService.selectTourTestItemsById(id));
    }

    /**
     * 新增巡考内容项
     */
    @RequiresPermissions("patrol:tourTestItems:add")
    @Log(title = "巡考内容项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TourTestItems tourTestItems)
    {
        return toAjax(tourTestItemsService.insertTourTestItems(tourTestItems));
    }

    /**
     * 修改巡考内容项
     */
    @RequiresPermissions("patrol:tourTestItems:edit")
    @Log(title = "巡考内容项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TourTestItems tourTestItems)
    {
        return toAjax(tourTestItemsService.updateTourTestItems(tourTestItems));
    }

    /**
     * 删除巡考内容项
     */
    @RequiresPermissions("patrol:tourTestItems:remove")
    @Log(title = "巡考内容项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tourTestItemsService.deleteTourTestItemsByIds(ids));
    }

    /**
     * 获取当前巡考表的具体情况记录
     */
    @GetMapping("/item/{tourTestId}")
    public List<TourTestItems> getTourTestItem(@PathVariable Long tourTestId) {
        return tourTestItemsService.getTourTestItemByTTId(tourTestId);
    }

    /**
     * 添加巡考具体情况记录
     */
    @PostMapping("/addTourTestEval")
    public AjaxResult addTourTestEval(@RequestBody List<TourTestItems> tourTestItemsList)
    {
        return toAjax(tourTestItemsService.insertTourTestEval(tourTestItemsList));
    }

    /**
     * 修改（更新）巡考具体情况记录
     */
    @PostMapping("/updateTourTestEval")
    public AjaxResult updateTourTestEval(@RequestBody List<TourTestItems> tourTestItemsList)
    {
        return toAjax(tourTestItemsService.updateTourTestEval(tourTestItemsList));
    }
}
